<?php

namespace Dddxiu\rules;

use Dddxiu\Layer;

/**
 * 数字字母
 */
class Alnum implements Rule
{
    // flag
    const F = 'w';


    /**
     * 校验
     * @param array $input
     * @param string $field
     * @param Layer $layer
     * @param array $args
     * @return \Closure|boolean
     * @throws \Exception
     */
    public static function valid($input, $field, $layer, $args)
    {
        $len = strlen($input[$field]);
        for ($i = 0; $i < $len; $i++) {
            if (!ctype_alnum($input[$field][$i])) {
                return false;
            }
        }
        return $layer::next(['type' => Layer::FIELD_TYPE_STR]);
    }
}